package com.huangyi;

public class Main {
    public static void main(String[] args) {
        //有效三角形个数
        class Solution {
            public int triangleNumber(int[] nums) {
                int count =0, n = nums.length-1;
                for(int i= n;i>=2;i--){
                    int right = i-1;
                    int left = 0;
                    while(left<right){
                        if(nums[right] + nums[left] > nums[i]){
                            count += right-left;
                            right--;
                        }else{
                            left++;
                        }
                    }
                }
                return count;
            }
        }


        //和为 S 的两个数字
        class Solution2 {
            public int[] twoSum(int[] price, int target) {
                int left =0, right = price.length-1;
                while(left<right){
                    int sum = price[left] + price[right];
                    if(sum == target){
                        return new int[] {price[left],price[right]};
                    }
                    if(sum < target){
                        left++;
                    }
                    if(sum > target){
                        right --;
                    }
                }
                return new int[] {0,-1};
            }
        }
    }
}